package com.wanghaixin.controller;

import com.wanghaixin.dto.DataGridResult;
import com.wanghaixin.dto.QueryDTO;
import com.wanghaixin.pojo.CarParamType;
import com.wanghaixin.pojo.CarParams;
import com.wanghaixin.service.CarParamTypeService;
import com.wanghaixin.service.CarParamsService;
import com.wanghaixin.utils.R;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @Auther: 王海新
 * @Date: 2020/11/2 10:47
 * @Description: 参数管理展示层
 */
@Controller
public class CarParamsConroller {

    @Autowired
    private CarParamsService carParamsService;

    @Autowired
    private CarParamTypeService carParamTypeService;


    /*********************************************************************************************************************
     * @Author:  王海新
     * @Date:  11:19  2020/11/2
     * @Version:  1.0.0
     * @Description:  分页查询
     */
    @RequestMapping("/sys/params/list")
    @ResponseBody
    public DataGridResult findByPage(QueryDTO queryDTO){
        DataGridResult byPage = carParamsService.findByPage(queryDTO);
        return byPage;
    }

    /*********************************************************************************************************************
     * @Author:  王海新
     * @Date:  11:19  2020/11/2
     * @Version:  1.0.0
     * @Description:  删除
     */
    @RequestMapping("/sys/params/del")
    @ResponseBody
    public R delCarParams(@RequestBody List<Integer> ids){
        for (Integer id : ids) {
            int i = carParamsService.delCarParams(id);
        }
        return R.ok();
    }

    /*********************************************************************************************************************
     * @Author:  王海新
     * @Date:  11:19  2020/11/2
     * @Version:  1.0.0
     * @Description:  获取分类信息的能力
     */
    @RequestMapping("/sys/params/typeall")
    @ResponseBody
    public R typeAll(){
        List<CarParamType> all = carParamTypeService.findAll();
        return R.ok().put("sites",all);
    }

    /*********************************************************************************************************************
     * @Author:  王海新
     * @Date:  11:20  2020/11/2
     * @Version:  1.0.0
     * @Description:  id查询
     */
    @RequestMapping("/sys/params/info/{id}")
    @ResponseBody
    public R findById(@PathVariable("id")Integer id){
        CarParams byId = carParamsService.findById(id);
        return R.ok().put("params",byId);
    }
    
    /*********************************************************************************************************************
     * @Author:  王海新
     * @Date:  11:22  2020/11/2
     * @Version:  1.0.0
     * @Description:  添加
     */
    @RequestMapping("/sys/params/save")
    @ResponseBody
    public R addCarParams(@RequestBody CarParams carParams){
        int i = carParamsService.addCarParams(carParams);
        return i>0 ? R.ok() : R.error("添加失败");
    }

    /*********************************************************************************************************************
     * @Author:  王海新
     * @Date:  11:22  2020/11/2
     * @Version:  1.0.0
     * @Description:  修改
     */
    @RequestMapping("/sys/params/update")
    @ResponseBody
    public R upCarParams(@RequestBody CarParams carParams){
        int i = carParamsService.upCarParams(carParams);
        return i> 0 ? R.ok() : R.error("修改失败");
    }


}
